package main.Q1001_1100;

public class Q1031_1040 {
	public static void main(String[] args) {
		System.out.println("Question1031：两个非重叠子数组的最大和");
		System.out.println("Question1032：");
		System.out.println("Question1033：");
		System.out.println("Question1034：");
		System.out.println("Question1035：");
		System.out.println("Question1036：");
		System.out.println("Question1037：");
		System.out.println("Question1038：从二叉搜索树到更大和树");
		System.out.println("Question1039：");
		System.out.println("Question1040：");
	}
}

class Question1031 {
	public int process(int[] nums, int len1, int len2) {
		int left = 0;
		for (int i = 0; i < len1; i++) {
			left += nums[i];
		}
		int maxLeft = left;
		int right = 0;
		for (int i = len1; i < len1 + len2; i++) {
			right += nums[i];
		}
		int result = maxLeft + right;
		for (int i = len1 + len2, j = len1; i < nums.length; i++, j++) {
			left += nums[j] - nums[j - len1];
			maxLeft = Math.max(maxLeft, left);
			right += nums[i] - nums[i - len2];
			result = Math.max(result, maxLeft + right);
		}
		return result;
	}

	public int maxSumTwoNoOverlap(int[] nums, int firstLen, int secondLen) {
		return Math.max(process(nums, firstLen, secondLen), process(nums, secondLen, firstLen));
	}
}

class Question1038 {

}